//
//  UIView.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/7/23.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import Foundation
import UIKit
/// MARK - UIView
extension UIView {
    
    // MARK: - 常用位置属性
    public var left:CGFloat {
        get {
            return self.frame.origin.x
        }
        set(newLeft) {
            var frame = self.frame
            frame.origin.x = newLeft
            self.frame = frame
        }
    }
    
    public var top:CGFloat {
        get {
            return self.frame.origin.y
        }
        
        set(newTop) {
            var frame = self.frame
            frame.origin.y = newTop
            self.frame = frame
        }
    }
    
    public var width:CGFloat {
        get {
            return self.frame.size.width
        }
        
        set(newWidth) {
            var frame = self.frame
            frame.size.width = newWidth
            self.frame = frame
        }
    }
    
    public var height:CGFloat {
        get {
            return self.frame.size.height
        }
        
        set(newHeight) {
            var frame = self.frame
            frame.size.height = newHeight
            self.frame = frame
        }
    }
    
    public var right:CGFloat {
        get {
            return self.left + self.width
        }
    }
    
    public var bottom:CGFloat {
        get {
            return self.top + self.height
        }
    }
    
    public var centerX:CGFloat {
        get {
            return self.center.x
        }
        
        set(newCenterX) {
            var center = self.center
            center.x = newCenterX
            self.center = center
        }
    }
    
    public var centerY:CGFloat {
        get {
            return self.center.y
        }
        
        set(newCenterY) {
            var center = self.center
            center.y = newCenterY
            self.center = center
        }
    }
    
    func setCornerRadio(radio:CGFloat,isMask:Bool){
        self.layer.cornerRadius = radio
        self.layer.masksToBounds = isMask
    }
    
    func corner(byRoundingCorners corners: UIRectCorner, radii: CGFloat) {
        let maskPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radii, height: radii))
        let maskLayer = CAShapeLayer()
        maskLayer.frame = self.bounds
        maskLayer.path = maskPath.cgPath
        self.layer.mask = maskLayer
    }
    
    // 添加阴影
    func setShadow(color:String,offset:CGSize,radius:CGFloat,opacity:Float) {
        self.layer.shadowColor = UIColor.init(hexColor: color).cgColor
        self.layer.shadowOffset = offset
        self.layer.shadowOpacity = opacity
        self.layer.shadowRadius = radius
    }
    
    func setBorder(color:String,width:CGFloat){
        self.layer.borderWidth = width
        self.layer.borderColor = UIColor.init(hexColor: color).cgColor
    }
    
}

extension UIScreen {
    class var ScreenWidth: CGFloat {
        return UIScreen.main.bounds.size.width
    }
    
    class var ScreenHeight: CGFloat {
        return UIScreen.main.bounds.size.height
    }
}




















